home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / racnab20.zip / PIPEBOMB.QC < prev    next >
Text File  |  1996-08-06  |  28KB  |  1,319 lines

  1. /*
  2.  Weapon related stuff
  3.  
  4.  Modifications by AsmodeusB
  5.  (28/07/96)
  6.    - Made W_SetCurrentAmmo() check if it's a player. (just a good idea)
  7.    - Added impulse 61 (6.1) to fire a pipebomb (grenade)
  8.      and impulse 62 which detonates all your pipebombs
  9. */
  10. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  11. void () player_run;
  12. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  13. void(vector org, vector vel, float damage) SpawnBlood;
  14. void() SuperDamageSound;
  15.  
  16.  
  17. // called by worldspawn
  18. void() W_Precache =
  19. {
  20.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  21.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  22.     precache_sound ("weapons/sgun1.wav");
  23.     precache_sound ("weapons/guncock.wav");    // player shotgun
  24.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  25.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  26.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  27.     precache_sound ("weapons/spike2.wav");    // super spikes
  28.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  29.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  30.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  31.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  32. };
  33.  
  34. float() crandom =
  35. {
  36.     return 2*(random() - 0.5);
  37. };
  38.  
  39. /*
  40. ================
  41. W_FireAxe
  42. ================
  43. */
  44. void() W_FireAxe =
  45. {
  46.     local    vector    source;
  47.     local    vector    org;
  48.  
  49.     source = self.origin + '0 0 16';
  50.     traceline (source, source + v_forward*64, FALSE, self);
  51.     if (trace_fraction == 1.0)
  52.         return;
  53.     
  54.     org = trace_endpos - v_forward*4;
  55.  
  56.     if (trace_ent.takedamage)
  57.     {
  58.         trace_ent.axhitme = 1;
  59.         SpawnBlood (org, '0 0 0', 20);
  60.         T_Damage (trace_ent, self, self, 20);
  61.     }
  62.     else
  63.     {    // hit wall
  64.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  65.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  66.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  67.         WriteCoord (MSG_BROADCAST, org_x);
  68.         WriteCoord (MSG_BROADCAST, org_y);
  69.         WriteCoord (MSG_BROADCAST, org_z);
  70.     }
  71. };
  72.  
  73.  
  74. //============================================================================
  75.  
  76.  
  77. vector() wall_velocity =
  78. {
  79.     local vector    vel;
  80.     
  81.     vel = normalize (self.velocity);
  82.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  83.     vel = vel + 2*trace_plane_normal;
  84.     vel = vel * 200;
  85.     
  86.     return vel;
  87. };
  88.  
  89.  
  90. /*
  91. ================
  92. SpawnMeatSpray
  93. ================
  94. */
  95. void(vector org, vector vel) SpawnMeatSpray =
  96. {
  97.     local    entity missile, mpuff;
  98.     local    vector    org;
  99.  
  100.     missile = spawn ();
  101.     missile.owner = self;
  102.     missile.movetype = MOVETYPE_BOUNCE;
  103.     missile.solid = SOLID_NOT;
  104.  
  105.     makevectors (self.angles);
  106.  
  107.     missile.velocity = vel;
  108.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  109.  
  110.     missile.avelocity = '3000 1000 2000';
  111.     
  112. // set missile duration
  113.     missile.nextthink = time + 1;
  114.     missile.think = SUB_Remove;
  115.  
  116.     setmodel (missile, "progs/zom_gib.mdl");
  117.     setsize (missile, '0 0 0', '0 0 0');        
  118.     setorigin (missile, org);
  119. };
  120.  
  121. /*
  122. ================
  123. SpawnBlood
  124. ================
  125. */
  126. void(vector org, vector vel, float damage) SpawnBlood =
  127. {
  128.     particle (org, vel*0.1, 73, damage*2);
  129. };
  130.  
  131. /*
  132. ================
  133. spawn_touchblood
  134. ================
  135. */
  136. void(float damage) spawn_touchblood =
  137. {
  138.     local vector    vel;
  139.  
  140.     vel = wall_velocity () * 0.2;
  141.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  142. };
  143.  
  144.  
  145. /*
  146. ================
  147. SpawnChunk
  148. ================
  149. */
  150. void(vector org, vector vel) SpawnChunk =
  151. {
  152.     particle (org, vel*0.02, 0, 10);
  153. };
  154.  
  155. /*
  156. ==============================================================================
  157.  
  158. MULTI-DAMAGE
  159.  
  160. Collects multiple small damages into a single damage
  161.  
  162. ==============================================================================
  163. */
  164.  
  165. entity    multi_ent;
  166. float    multi_damage;
  167.  
  168. void() ClearMultiDamage =
  169. {
  170.     multi_ent = world;
  171.     multi_damage = 0;
  172. };
  173.  
  174. void() ApplyMultiDamage =
  175. {
  176.     if (!multi_ent)
  177.         return;
  178.     T_Damage (multi_ent, self, self, multi_damage);
  179. };
  180.  
  181. void(entity hit, float damage) AddMultiDamage =
  182. {
  183.     if (!hit)
  184.         return;
  185.     
  186.     if (hit != multi_ent)
  187.     {
  188.         ApplyMultiDamage ();
  189.         multi_damage = damage;
  190.         multi_ent = hit;
  191.     }
  192.     else
  193.         multi_damage = multi_damage + damage;
  194. };
  195.  
  196. /*
  197. ==============================================================================
  198.  
  199. BULLETS
  200.  
  201. ==============================================================================
  202. */
  203.  
  204. /*
  205. ================
  206. TraceAttack
  207. ================
  208. */
  209. void(float damage, vector dir) TraceAttack =
  210. {
  211.     local    vector    vel, org;
  212.     
  213.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  214.     vel = vel + 2*trace_plane_normal;
  215.     vel = vel * 200;
  216.  
  217.     org = trace_endpos - dir*4;
  218.  
  219.     if (trace_ent.takedamage)
  220.     {
  221.         SpawnBlood (org, vel*0.2, damage);
  222.         AddMultiDamage (trace_ent, damage);
  223.     }
  224.     else
  225.     {
  226.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  227.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  228.         WriteCoord (MSG_BROADCAST, org_x);
  229.         WriteCoord (MSG_BROADCAST, org_y);
  230.         WriteCoord (MSG_BROADCAST, org_z);
  231.     }
  232. };
  233.  
  234. /*
  235. ================
  236. FireBullets
  237.  
  238. Used by shotgun, super shotgun, and enemy soldier firing
  239. Go to the trouble of combining multiple pellets into a single damage call.
  240. ================
  241. */
  242. void(float shotcount, vector dir, vector spread) FireBullets =
  243. {
  244.     local    vector direction;
  245.     local    vector    src;
  246.     
  247.     makevectors(self.v_angle);
  248.  
  249.     src = self.origin + v_forward*10;
  250.     src_z = self.absmin_z + self.size_z * 0.7;
  251.  
  252.     ClearMultiDamage ();
  253.     while (shotcount > 0)
  254.     {
  255.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  256.  
  257.         traceline (src, src + direction*2048, FALSE, self);
  258.         if (trace_fraction != 1.0)
  259.             TraceAttack (4, direction);
  260.  
  261.         shotcount = shotcount - 1;
  262.     }
  263.     ApplyMultiDamage ();
  264. };
  265.  
  266. /*
  267. ================
  268. W_FireShotgun
  269. ================
  270. */
  271. void() W_FireShotgun =
  272. {
  273.     local vector dir;
  274.  
  275.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  276.  
  277.     self.punchangle_x = -2;
  278.     
  279.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  280.     dir = aim (self, 100000);
  281.     FireBullets (6, dir, '0.04 0.04 0');
  282. };
  283.  
  284.  
  285. /*
  286. ================
  287. W_FireSuperShotgun
  288. ================
  289. */
  290. void() W_FireSuperShotgun =
  291. {
  292.     local vector dir;
  293.  
  294.     if (self.currentammo == 1)
  295.     {
  296.         W_FireShotgun ();
  297.         return;
  298.     }
  299.         
  300.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  301.  
  302.     self.punchangle_x = -4;
  303.     
  304.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  305.     dir = aim (self, 100000);
  306.     FireBullets (14, dir, '0.14 0.08 0');
  307. };
  308.  
  309.  
  310. /*
  311. ==============================================================================
  312.  
  313. ROCKETS
  314.  
  315. ==============================================================================
  316. */
  317.  
  318. void()    s_explode1    =    [0,        s_explode2] {};
  319. void()    s_explode2    =    [1,        s_explode3] {};
  320. void()    s_explode3    =    [2,        s_explode4] {};
  321. void()    s_explode4    =    [3,        s_explode5] {};
  322. void()    s_explode5    =    [4,        s_explode6] {};
  323. void()    s_explode6    =    [5,        SUB_Remove] {};
  324.  
  325. void() BecomeExplosion =
  326. {
  327.     self.movetype = MOVETYPE_NONE;
  328.     self.velocity = '0 0 0';
  329.     self.touch = SUB_Null;
  330.     setmodel (self, "progs/s_explod.spr");
  331.     self.solid = SOLID_NOT;
  332.     s_explode1 ();
  333. };
  334.  
  335. void() T_MissileTouch =
  336. {
  337.     local float    damg;
  338.  
  339.     if (other == self.owner)
  340.         return;        // don't explode on owner
  341.  
  342.     if (pointcontents(self.origin) == CONTENT_SKY)
  343.     {
  344.         remove(self);
  345.         return;
  346.     }
  347.  
  348.     damg = 100 + random()*20;
  349.     
  350.     if (other.health)
  351.     {
  352.         if (other.classname == "monster_shambler")
  353.             damg = damg * 0.5;    // mostly immune
  354.         T_Damage (other, self, self.owner, damg );
  355.     }
  356.  
  357.     // don't do radius damage to the other, because all the damage
  358.     // was done in the impact
  359.     T_RadiusDamage (self, self.owner, 120, other);
  360.  
  361. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  362.     self.origin = self.origin - 8*normalize(self.velocity);
  363.  
  364.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  365.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  366.     WriteCoord (MSG_BROADCAST, self.origin_x);
  367.     WriteCoord (MSG_BROADCAST, self.origin_y);
  368.     WriteCoord (MSG_BROADCAST, self.origin_z);
  369.  
  370.     BecomeExplosion ();
  371. };
  372.  
  373.  
  374.  
  375. /*
  376. ================
  377. W_FireRocket
  378. ================
  379. */
  380. void() W_FireRocket =
  381. {
  382.     local    entity missile, mpuff;
  383.     
  384.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  385.     
  386.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  387.  
  388.     self.punchangle_x = -2;
  389.  
  390.     missile = spawn ();
  391.     missile.owner = self;
  392.     missile.movetype = MOVETYPE_FLYMISSILE;
  393.     missile.solid = SOLID_BBOX;
  394.         
  395. // set missile speed    
  396.  
  397.     makevectors (self.v_angle);
  398.     missile.velocity = aim(self, 1000);
  399.     missile.velocity = missile.velocity * 1000;
  400.     missile.angles = vectoangles(missile.velocity);
  401.     
  402.     missile.touch = T_MissileTouch;
  403.     
  404. // set missile duration
  405.     missile.nextthink = time + 5;
  406.     missile.think = SUB_Remove;
  407.  
  408.     setmodel (missile, "progs/missile.mdl");
  409.     setsize (missile, '0 0 0', '0 0 0');        
  410.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  411. };
  412.  
  413. /*
  414. ===============================================================================
  415.  
  416. LIGHTNING
  417.  
  418. ===============================================================================
  419. */
  420.  
  421. /*
  422. =================
  423. LightningDamage
  424. =================
  425. */
  426. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  427. {
  428.     local entity        e1, e2;
  429.     local vector        f;
  430.     
  431.     f = p2 - p1;
  432.     normalize (f);
  433.     f_x = 0 - f_y;
  434.     f_y = f_x;
  435.     f_z = 0;
  436.     f = f*16;
  437.  
  438.     e1 = e2 = world;
  439.  
  440.     traceline (p1, p2, FALSE, self);
  441.     if (trace_ent.takedamage)
  442.     {
  443.         particle (trace_endpos, '0 0 100', 225, damage*4);
  444.         T_Damage (trace_ent, from, from, damage);
  445.         if (self.classname == "player")
  446.         {
  447.             if (other.classname == "player")
  448.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  449.         }
  450.     }
  451.     e1 = trace_ent;
  452.  
  453.     traceline (p1 + f, p2 + f, FALSE, self);
  454.     if (trace_ent != e1 && trace_ent.takedamage)
  455.     {
  456.         particle (trace_endpos, '0 0 100', 225, damage*4);
  457.         T_Damage (trace_ent, from, from, damage);
  458.     }
  459.     e2 = trace_ent;
  460.  
  461.     traceline (p1 - f, p2 - f, FALSE, self);
  462.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  463.     {
  464.         particle (trace_endpos, '0 0 100', 225, damage*4);
  465.         T_Damage (trace_ent, from, from, damage);
  466.     }
  467. };
  468.  
  469.  
  470. void() W_FireLightning =
  471. {
  472.     local    vector        org;
  473.  
  474.     if (self.ammo_cells < 1)
  475.     {
  476.         self.weapon = W_BestWeapon ();
  477.         W_SetCurrentAmmo ();
  478.         return;
  479.     }
  480.  
  481. // explode if under water
  482.     if (self.waterlevel > 1)
  483.     {
  484.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  485.         self.ammo_cells = 0;
  486.         W_SetCurrentAmmo ();
  487.         return;
  488.     }
  489.  
  490.     if (self.t_width < time)
  491.     {
  492.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  493.         self.t_width = time + 0.6;
  494.     }
  495.     self.punchangle_x = -2;
  496.  
  497.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  498.  
  499.     org = self.origin + '0 0 16';
  500.     
  501.     traceline (org, org + v_forward*600, TRUE, self);
  502.  
  503.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  504.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  505.     WriteEntity (MSG_BROADCAST, self);
  506.     WriteCoord (MSG_BROADCAST, org_x);
  507.     WriteCoord (MSG_BROADCAST, org_y);
  508.     WriteCoord (MSG_BROADCAST, org_z);
  509.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  510.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  511.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  512.  
  513.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  514. };
  515.  
  516.  
  517. //=============================================================================
  518.  
  519.  
  520. void() GrenadeExplode =
  521. {
  522.     T_RadiusDamage (self, self.owner, 120, world);
  523.  
  524.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  525.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  526.     WriteCoord (MSG_BROADCAST, self.origin_x);
  527.     WriteCoord (MSG_BROADCAST, self.origin_y);
  528.     WriteCoord (MSG_BROADCAST, self.origin_z);
  529.  
  530.     BecomeExplosion ();
  531. };
  532.  
  533. void() GrenadeTouch =
  534. {
  535.     if (other == self.owner)
  536.         return;        // don't explode on owner
  537.     if (other.takedamage == DAMAGE_AIM)
  538.     {
  539.         GrenadeExplode();
  540.         return;
  541.     }
  542.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  543.     if (self.velocity == '0 0 0')
  544.         self.avelocity = '0 0 0';
  545. };
  546.  
  547. /*
  548. ================
  549. W_FireGrenade
  550. ================
  551. */
  552. void() W_FireGrenade =
  553. {
  554.     local    entity missile, mpuff;
  555.     
  556.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  557.     
  558.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  559.  
  560.     self.punchangle_x = -2;
  561.  
  562.     missile = spawn ();
  563.     missile.owner = self;
  564.     missile.movetype = MOVETYPE_BOUNCE;
  565.     missile.solid = SOLID_BBOX;
  566.     missile.classname = "grenade";
  567.         
  568. // set missile speed    
  569.  
  570.     makevectors (self.v_angle);
  571.  
  572.     if (self.v_angle_x)
  573.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  574.     else
  575.     {
  576.         missile.velocity = aim(self, 10000);
  577.         missile.velocity = missile.velocity * 600;
  578.         missile.velocity_z = 200;
  579.     }
  580.  
  581.     missile.avelocity = '300 300 300';
  582.  
  583.     missile.angles = vectoangles(missile.velocity);
  584.     
  585.     missile.touch = GrenadeTouch;
  586.     
  587. // set missile duration
  588.     missile.nextthink = time + 2.5;
  589.     missile.think = GrenadeExplode;
  590.  
  591.     setmodel (missile, "progs/grenade.mdl");
  592.     setsize (missile, '0 0 0', '0 0 0');        
  593.     setorigin (missile, self.origin);
  594. };
  595.  
  596.  
  597. //=============================================================================
  598.  
  599. void() spike_touch;
  600. void() superspike_touch;
  601.  
  602.  
  603. /*
  604. ===============
  605. launch_spike
  606.  
  607. Used for both the player and the ogre
  608. ===============
  609. */
  610. void(vector org, vector dir) launch_spike =
  611. {
  612.     newmis = spawn ();
  613.     newmis.owner = self;
  614.     newmis.movetype = MOVETYPE_FLYMISSILE;
  615.     newmis.solid = SOLID_BBOX;
  616.  
  617.     newmis.angles = vectoangles(dir);
  618.     
  619.     newmis.touch = spike_touch;
  620.     newmis.classname = "spike";
  621.     newmis.think = SUB_Remove;
  622.     newmis.nextthink = time + 6;
  623.     setmodel (newmis, "progs/spike.mdl");
  624.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  625.     setorigin (newmis, org);
  626.  
  627.     newmis.velocity = dir * 1000;
  628. };
  629.  
  630. void() W_FireSuperSpikes =
  631. {
  632.     local vector    dir;
  633.     local entity    old;
  634.     
  635.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  636.     self.attack_finished = time + 0.2;
  637.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  638.     dir = aim (self, 1000);
  639.     launch_spike (self.origin + '0 0 16', dir);
  640.     newmis.touch = superspike_touch;
  641.     setmodel (newmis, "progs/s_spike.mdl");
  642.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  643.     self.punchangle_x = -2;
  644. };
  645.  
  646. void(float ox) W_FireSpikes =
  647. {
  648.     local vector    dir;
  649.     local entity    old;
  650.     
  651.     makevectors (self.v_angle);
  652.     
  653.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  654.     {
  655.         W_FireSuperSpikes ();
  656.         return;
  657.     }
  658.  
  659.     if (self.ammo_nails < 1)
  660.     {
  661.         self.weapon = W_BestWeapon ();
  662.         W_SetCurrentAmmo ();
  663.         return;
  664.     }
  665.  
  666.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  667.     self.attack_finished = time + 0.2;
  668.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  669.     dir = aim (self, 1000);
  670.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  671.  
  672.     self.punchangle_x = -2;
  673. };
  674.  
  675.  
  676. .float hit_z;
  677. void() spike_touch =
  678. {
  679. local float rand;
  680.     if (other == self.owner)
  681.         return;
  682.  
  683.     if (other.solid == SOLID_TRIGGER)
  684.         return;    // trigger field, do nothing
  685.  
  686.     if (pointcontents(self.origin) == CONTENT_SKY)
  687.     {
  688.         remove(self);
  689.         return;
  690.     }
  691.     
  692. // hit something that bleeds
  693.     if (other.takedamage)
  694.     {
  695.         spawn_touchblood (9);
  696.         T_Damage (other, self, self.owner, 9);
  697.     }
  698.     else
  699.     {
  700.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  701.         
  702.         if (self.classname == "wizspike")
  703.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  704.         else if (self.classname == "knightspike")
  705.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  706.         else
  707.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  708.         WriteCoord (MSG_BROADCAST, self.origin_x);
  709.         WriteCoord (MSG_BROADCAST, self.origin_y);
  710.         WriteCoord (MSG_BROADCAST, self.origin_z);
  711.     }
  712.  
  713.     remove(self);
  714. };
  715.  
  716. void() superspike_touch =
  717. {
  718. local float rand;
  719.     if (other == self.owner)
  720.         return;
  721.  
  722.     if (other.solid == SOLID_TRIGGER)
  723.         return;    // trigger field, do nothing
  724.  
  725.     if (pointcontents(self.origin) == CONTENT_SKY)
  726.     {
  727.         remove(self);
  728.         return;
  729.     }
  730.     
  731. // hit something that bleeds
  732.     if (other.takedamage)
  733.     {
  734.         spawn_touchblood (18);
  735.         T_Damage (other, self, self.owner, 18);
  736.     }
  737.     else
  738.     {
  739.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  740.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  741.         WriteCoord (MSG_BROADCAST, self.origin_x);
  742.         WriteCoord (MSG_BROADCAST, self.origin_y);
  743.         WriteCoord (MSG_BROADCAST, self.origin_z);
  744.     }
  745.  
  746.     remove(self);
  747.  
  748. };
  749.  
  750. /*
  751.  ------------------------------------------
  752.  Pipe Bombs
  753.  ------------------------------------------
  754. */
  755.  
  756. /*
  757.  * Blow up the toys.  There is a range of 1000 units (pixels?), so you can't
  758.  * go wandering off.
  759.  */
  760.  
  761. void() DetPipeBombs =
  762. {
  763.         local entity    head;
  764.  
  765.         head = findradius (self.origin, 1000);
  766.         while(head)
  767.         {
  768.                 if((head.classname == "pipebomb") && (head.owner == self))
  769.                         head.nextthink = time;
  770.                 head = head.chain;
  771.         }
  772. };
  773.  
  774. /*
  775.  * What happens if it touches something
  776.  */
  777.  
  778. void() PipeBombTouch =
  779. {
  780.     if (other == self.owner)
  781.         return;        // don't explode on owner
  782.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  783.     if (self.velocity == '0 0 0')
  784.         self.avelocity = '0 0 0';
  785. };
  786.  
  787. /*
  788.  * Fires a pipe bomb.  Can be detonated at any time.  Doesn't need a special
  789.  * weapon selected.
  790.  */
  791.  
  792. void() W_FirePipeBomb =
  793. {
  794.     local    entity missile, mpuff;
  795.     
  796.     if(self.ammo_rockets < 1)    // have to have ammo
  797.       return;
  798.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  799.     
  800. //    sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  801.  
  802. //    self.punchangle_x = -2;
  803.  
  804.     missile = spawn ();
  805.     missile.owner = self;
  806.     missile.movetype = MOVETYPE_BOUNCE;
  807.     missile.solid = SOLID_BBOX;
  808.     missile.classname = "pipebomb";
  809.         
  810. // set missile speed    
  811.  
  812.     makevectors (self.v_angle);
  813.  
  814.     if (self.v_angle_x)
  815.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  816.     else
  817.     {
  818.         missile.velocity = aim(self, 10000);
  819.         missile.velocity = missile.velocity * 600;
  820.         missile.velocity_z = 200;
  821.     }
  822.  
  823.     missile.avelocity = '300 300 300';
  824.  
  825.     missile.angles = vectoangles(missile.velocity);
  826.     
  827.     missile.touch = PipeBombTouch;
  828.     missile.think = GrenadeExplode;
  829.     
  830.     setmodel (missile, "progs/grenade.mdl");
  831.     setsize (missile, '0 0 0', '0 0 0');        
  832.     setorigin (missile, self.origin);
  833. };
  834.  
  835. /*
  836. ===============================================================================
  837.  
  838. PLAYER WEAPON USE
  839.  
  840. ===============================================================================
  841. */
  842.  
  843. void() W_SetCurrentAmmo =
  844. {
  845.  if(self.classname != "player")
  846.    return;
  847.    
  848.     player_run ();        // get out of any weapon firing states
  849.  
  850.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  851.     
  852.     if (self.weapon == IT_AXE)
  853.     {
  854.         self.currentammo = 0;
  855.         self.weaponmodel = "progs/v_axe.mdl";
  856.         self.weaponframe = 0;
  857.     }
  858.     else if (self.weapon == IT_SHOTGUN)
  859.     {
  860.         self.currentammo = self.ammo_shells;
  861.         self.weaponmodel = "progs/v_shot.mdl";
  862.         self.weaponframe = 0;
  863.         self.items = self.items | IT_SHELLS;
  864.     }
  865.     else if (self.weapon == IT_SUPER_SHOTGUN)
  866.     {
  867.         self.currentammo = self.ammo_shells;
  868.         self.weaponmodel = "progs/v_shot2.mdl";
  869.         self.weaponframe = 0;
  870.         self.items = self.items | IT_SHELLS;
  871.     }
  872.     else if (self.weapon == IT_NAILGUN)
  873.     {
  874.         self.currentammo = self.ammo_nails;
  875.         self.weaponmodel = "progs/v_nail.mdl";
  876.         self.weaponframe = 0;
  877.         self.items = self.items | IT_NAILS;
  878.     }
  879.     else if (self.weapon == IT_SUPER_NAILGUN)
  880.     {
  881.         self.currentammo = self.ammo_nails;
  882.         self.weaponmodel = "progs/v_nail2.mdl";
  883.         self.weaponframe = 0;
  884.         self.items = self.items | IT_NAILS;
  885.     }
  886.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  887.     {
  888.         self.currentammo = self.ammo_rockets;
  889.         self.weaponmodel = "progs/v_rock.mdl";
  890.         self.weaponframe = 0;
  891.         self.items = self.items | IT_ROCKETS;
  892.     }
  893.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  894.     {
  895.         self.currentammo = self.ammo_rockets;
  896.         self.weaponmodel = "progs/v_rock2.mdl";
  897.         self.weaponframe = 0;
  898.         self.items = self.items | IT_ROCKETS;
  899.     }
  900.     else if (self.weapon == IT_LIGHTNING)
  901.     {
  902.         self.currentammo = self.ammo_cells;
  903.         self.weaponmodel = "progs/v_light.mdl";
  904.         self.weaponframe = 0;
  905.         self.items = self.items | IT_CELLS;
  906.     }
  907.     else
  908.     {
  909.         self.currentammo = 0;
  910.         self.weaponmodel = "";
  911.         self.weaponframe = 0;
  912.     }
  913. };
  914.  
  915. float() W_BestWeapon =
  916. {
  917.     local    float    it;
  918.     
  919.     it = self.items;
  920.  
  921.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  922.         return IT_LIGHTNING;
  923.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  924.         return IT_SUPER_NAILGUN;
  925.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  926.         return IT_SUPER_SHOTGUN;
  927.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  928.         return IT_NAILGUN;
  929.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  930.         return IT_SHOTGUN;
  931.         
  932. /*
  933.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  934.         return IT_ROCKET_LAUNCHER;
  935.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  936.         return IT_GRENADE_LAUNCHER;
  937.  
  938. */
  939.  
  940.     return IT_AXE;
  941. };
  942.  
  943. float() W_CheckNoAmmo =
  944. {
  945.     if (self.currentammo > 0)
  946.         return TRUE;
  947.  
  948.     if (self.weapon == IT_AXE)
  949.         return TRUE;
  950.     
  951.     self.weapon = W_BestWeapon ();
  952.  
  953.     W_SetCurrentAmmo ();
  954.     
  955. // drop the weapon down
  956.     return FALSE;
  957. };
  958.  
  959. /*
  960. ============
  961. W_Attack
  962.  
  963. An attack impulse can be triggered now
  964. ============
  965. */
  966. void()    player_axe1;
  967. void()    player_axeb1;
  968. void()    player_axec1;
  969. void()    player_axed1;
  970. void()    player_shot1;
  971. void()    player_nail1;
  972. void()    player_light1;
  973. void()    player_rocket1;
  974.  
  975. void() W_Attack =
  976. {
  977.     local    float    r;
  978.  
  979.     if (!W_CheckNoAmmo ())
  980.         return;
  981.  
  982.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  983.     self.show_hostile = time + 1;    // wake monsters up
  984.  
  985.     if (self.weapon == IT_AXE)
  986.     {
  987.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  988.         r = random();
  989.         if (r < 0.25)
  990.             player_axe1 ();
  991.         else if (r<0.5)
  992.             player_axeb1 ();
  993.         else if (r<0.75)
  994.             player_axec1 ();
  995.         else
  996.             player_axed1 ();
  997.         self.attack_finished = time + 0.5;
  998.     }
  999.     else if (self.weapon == IT_SHOTGUN)
  1000.     {
  1001.         player_shot1 ();
  1002.         W_FireShotgun ();
  1003.         self.attack_finished = time + 0.5;
  1004.     }
  1005.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1006.     {
  1007.         player_shot1 ();
  1008.         W_FireSuperShotgun ();
  1009.         self.attack_finished = time + 0.7;
  1010.     }
  1011.     else if (self.weapon == IT_NAILGUN)
  1012.     {
  1013.         player_nail1 ();
  1014.     }
  1015.     else if (self.weapon == IT_SUPER_NAILGUN)
  1016.     {
  1017.         player_nail1 ();
  1018.     }
  1019.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1020.     {
  1021.         player_rocket1();
  1022.         W_FireGrenade();
  1023.         self.attack_finished = time + 0.6;
  1024.     }
  1025.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1026.     {
  1027.         player_rocket1();
  1028.         W_FireRocket();
  1029.         self.attack_finished = time + 0.8;
  1030.     }
  1031.     else if (self.weapon == IT_LIGHTNING)
  1032.     {
  1033.         player_light1();
  1034.         self.attack_finished = time + 0.1;
  1035.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1036.     }
  1037. };
  1038.  
  1039. /*
  1040. ============
  1041. W_ChangeWeapon
  1042.  
  1043. ============
  1044. */
  1045. void() W_ChangeWeapon =
  1046. {
  1047.     local    float    it, am, fl;
  1048.     
  1049.     it = self.items;
  1050.     am = 0;
  1051.     
  1052.     if (self.impulse == 1)
  1053.     {
  1054.         fl = IT_AXE;
  1055.     }
  1056.     else if (self.impulse == 2)
  1057.     {
  1058.         fl = IT_SHOTGUN;
  1059.         if (self.ammo_shells < 1)
  1060.             am = 1;
  1061.     }
  1062.     else if (self.impulse == 3)
  1063.     {
  1064.         fl = IT_SUPER_SHOTGUN;
  1065.         if (self.ammo_shells < 2)
  1066.             am = 1;
  1067.     }        
  1068.     else if (self.impulse == 4)
  1069.     {
  1070.         fl = IT_NAILGUN;
  1071.         if (self.ammo_nails < 1)
  1072.             am = 1;
  1073.     }
  1074.     else if (self.impulse == 5)
  1075.     {
  1076.         fl = IT_SUPER_NAILGUN;
  1077.         if (self.ammo_nails < 2)
  1078.             am = 1;
  1079.     }
  1080.     else if (self.impulse == 6)
  1081.     {
  1082.         fl = IT_GRENADE_LAUNCHER;
  1083.         if (self.ammo_rockets < 1)
  1084.             am = 1;
  1085.     }
  1086.     else if (self.impulse == 7)
  1087.     {
  1088.         fl = IT_ROCKET_LAUNCHER;
  1089.         if (self.ammo_rockets < 1)
  1090.             am = 1;
  1091.     }
  1092.     else if (self.impulse == 8)
  1093.     {
  1094.         fl = IT_LIGHTNING;
  1095.         if (self.ammo_cells < 1)
  1096.             am = 1;
  1097.     }
  1098.  
  1099.     self.impulse = 0;
  1100.     
  1101.     if (!(self.items & fl))
  1102.     {    // don't have the weapon or the ammo
  1103.         sprint (self, "no weapon.\n");
  1104.         return;
  1105.     }
  1106.     
  1107.     if (am)
  1108.     {    // don't have the ammo
  1109.         sprint (self, "not enough ammo.\n");
  1110.         return;
  1111.     }
  1112.  
  1113. //
  1114. // set weapon, set ammo
  1115. //
  1116.     self.weapon = fl;        
  1117.     W_SetCurrentAmmo ();
  1118. };
  1119.  
  1120. /*
  1121. ============
  1122. CheatCommand
  1123. ============
  1124. */
  1125. void() CheatCommand =
  1126. {
  1127.     if (deathmatch || coop)
  1128.         return;
  1129.  
  1130.     self.ammo_rockets = 100;
  1131.     self.ammo_nails = 200;
  1132.     self.ammo_shells = 100;
  1133.     self.items = self.items | 
  1134.         IT_AXE |
  1135.         IT_SHOTGUN |
  1136.         IT_SUPER_SHOTGUN |
  1137.         IT_NAILGUN |
  1138.         IT_SUPER_NAILGUN |
  1139.         IT_GRENADE_LAUNCHER |
  1140.         IT_ROCKET_LAUNCHER |
  1141.         IT_KEY1 | IT_KEY2;
  1142.  
  1143.     self.ammo_cells = 200;
  1144.     self.items = self.items | IT_LIGHTNING;
  1145.  
  1146.     self.weapon = IT_ROCKET_LAUNCHER;
  1147.     self.impulse = 0;
  1148.     W_SetCurrentAmmo ();
  1149. };
  1150.  
  1151. /*
  1152. ============
  1153. CycleWeaponCommand
  1154.  
  1155. Go to the next weapon with ammo
  1156. ============
  1157. */
  1158. void() CycleWeaponCommand =
  1159. {
  1160.     local    float    it, am;
  1161.     
  1162.     it = self.items;
  1163.     self.impulse = 0;
  1164.     
  1165.     while (1)
  1166.     {
  1167.         am = 0;
  1168.  
  1169.         if (self.weapon == IT_LIGHTNING)
  1170.         {
  1171.             self.weapon = IT_AXE;
  1172.         }
  1173.         else if (self.weapon == IT_AXE)
  1174.         {
  1175.             self.weapon = IT_SHOTGUN;
  1176.             if (self.ammo_shells < 1)
  1177.                 am = 1;
  1178.         }
  1179.         else if (self.weapon == IT_SHOTGUN)
  1180.         {
  1181.             self.weapon = IT_SUPER_SHOTGUN;
  1182.             if (self.ammo_shells < 2)
  1183.                 am = 1;
  1184.         }        
  1185.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1186.         {
  1187.             self.weapon = IT_NAILGUN;
  1188.             if (self.ammo_nails < 1)
  1189.                 am = 1;
  1190.         }
  1191.         else if (self.weapon == IT_NAILGUN)
  1192.         {
  1193.             self.weapon = IT_SUPER_NAILGUN;
  1194.             if (self.ammo_nails < 2)
  1195.                 am = 1;
  1196.         }
  1197.         else if (self.weapon == IT_SUPER_NAILGUN)
  1198.         {
  1199.             self.weapon = IT_GRENADE_LAUNCHER;
  1200.             if (self.ammo_rockets < 1)
  1201.                 am = 1;
  1202.         }
  1203.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1204.         {
  1205.             self.weapon = IT_ROCKET_LAUNCHER;
  1206.             if (self.ammo_rockets < 1)
  1207.                 am = 1;
  1208.         }
  1209.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1210.         {
  1211.             self.weapon = IT_LIGHTNING;
  1212.             if (self.ammo_cells < 1)
  1213.                 am = 1;
  1214.         }
  1215.     
  1216.         if ( (self.items & self.weapon) && am == 0)
  1217.         {
  1218.             W_SetCurrentAmmo ();
  1219.             return;
  1220.         }
  1221.     }
  1222.  
  1223. };
  1224.  
  1225. /*
  1226. ============
  1227. ServerflagsCommand
  1228.  
  1229. Just for development
  1230. ============
  1231. */
  1232. void() ServerflagsCommand =
  1233. {
  1234.     serverflags = serverflags * 2 + 1;
  1235. };
  1236.  
  1237. void() QuadCheat =
  1238. {
  1239.     if (deathmatch || coop)
  1240.         return;
  1241.     self.super_time = 1;
  1242.     self.super_damage_finished = time + 30;
  1243.     self.items = self.items | IT_QUAD;
  1244.     dprint ("quad cheat\n");
  1245. };
  1246.  
  1247. /*
  1248. ============
  1249. ImpulseCommands
  1250.  
  1251. ============
  1252. */
  1253. void() ImpulseCommands =
  1254. {
  1255.     if (self.impulse >= 1 && self.impulse <= 8)
  1256.         W_ChangeWeapon ();
  1257.  
  1258.     if (self.impulse == 9)
  1259.         CheatCommand ();
  1260.     if (self.impulse == 10)
  1261.         CycleWeaponCommand ();
  1262.     if (self.impulse == 11)
  1263.         ServerflagsCommand ();
  1264.  
  1265.     if(self.impulse == 61)
  1266.       W_FirePipeBomb();
  1267.     if(self.impulse == 62)
  1268.       DetPipeBombs();
  1269.  
  1270.     if (self.impulse == 255)
  1271.         QuadCheat ();
  1272.         
  1273.     self.impulse = 0;
  1274. };
  1275.  
  1276. /*
  1277. ============
  1278. W_WeaponFrame
  1279.  
  1280. Called every frame so impulse events can be handled as well as possible
  1281. ============
  1282. */
  1283. void() W_WeaponFrame =
  1284. {
  1285.     if (time < self.attack_finished)
  1286.         return;
  1287.  
  1288.     ImpulseCommands ();
  1289.     
  1290. // check for attack
  1291.     if (self.button0)
  1292.     {
  1293.         SuperDamageSound ();
  1294.         W_Attack ();
  1295.     }
  1296. };
  1297.  
  1298. /*
  1299. ========
  1300. SuperDamageSound
  1301.  
  1302. Plays sound if needed
  1303. ========
  1304. */
  1305. void() SuperDamageSound =
  1306. {
  1307.     if (self.super_damage_finished > time)
  1308.     {
  1309.         if (self.super_sound < time)
  1310.         {
  1311.             self.super_sound = time + 1;
  1312.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1313.         }
  1314.     }
  1315.     return;
  1316. };
  1317.  
  1318.  
  1319.